﻿//=========================================================================
//Author:  UnKnow
//Create Data:  UnKnow
//Description:  DALPayAndReceiveItem[Get And REWrite by Zeinali,Farshad]
//Email:  farshadz70@gmail.com
//Mobile:  0912_6467348
//LastUpdata:  1390/02/24 00:51
//Important:  lotfan kasi bedon hamahangi man Class ro taghir nade
//=========================================================================
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;

namespace ChequeManagement.DAL
{
    /// <summary>
    /// this class contain methods for connect to dataBase 
    /// this methods are Insert,Update,FetchAll,Delete,InitialObjectsFromReader,InitialBusinessObjectsFromReader
    /// this class inheritance of BaseDAL
    /// </summary>
    public class DALPayAndReceiveItem : BaseDAL
    {
        /// <summary>
        /// this constructor called base constructor and set parameter
        /// parameter value is Connectionstring for connect to dataBase
        /// </summary>
        public DALPayAndReceiveItem()
            : base(ChequeManagement.Properties.Settings.Default.Database1ConnectionString)
        {
        }
        /// <summary>
        /// this method is for insert a object of BLL.BLLPayAndReceiveItem to table
        /// this method check connection if connection is open insert object to table
        /// </summary>
        /// <param name="payAndReceiveItemObject" Type="BLL.BLLPayAndReceiveItem"></param>
        /// <return>this type is void and Do not return</return>
        public void Insert(BLL.BLLPayAndReceiveItem payAndReceiveItemObject)
        {
            bool controlConnection = !(this.ConnectionState == System.Data.ConnectionState.Open);
            this.Command.CommandText = "uspPayAndReceiveItemInsert";
            this.Command.CommandType = CommandType.StoredProcedure;

            try
            {
                this.Command.Parameters.Clear();

                SqlParameter AccountNo = new SqlParameter();
                AccountNo.ParameterName = "@AccountNo";
                AccountNo.SqlDbType = SqlDbType.BigInt;
                AccountNo.Direction = ParameterDirection.Input;
                AccountNo.IsNullable = false;
                AccountNo.Value = payAndReceiveItemObject.AcountNo;
                this.Command.Parameters.Add(AccountNo);

                SqlParameter Amount = new SqlParameter();
                Amount.ParameterName = "@Amount";
                Amount.SqlDbType = SqlDbType.BigInt;
                Amount.Direction = ParameterDirection.Input;
                Amount.IsNullable = false;
                Amount.Value = payAndReceiveItemObject.Amount;
                this.Command.Parameters.Add(Amount);

                SqlParameter BranchName = new SqlParameter();
                BranchName.ParameterName = "@BranchName";
                BranchName.SqlDbType = SqlDbType.NVarChar;
                BranchName.Direction = ParameterDirection.Input;
                BranchName.IsNullable = false;
                BranchName.Value = payAndReceiveItemObject.BranchName;
                this.Command.Parameters.Add(BranchName);

                SqlParameter BankID = new SqlParameter();
                BankID.ParameterName = "@BankID";
                BankID.SqlDbType = SqlDbType.Int;
                BankID.Direction = ParameterDirection.Input;
                BankID.IsNullable = false;
                BankID.Value = payAndReceiveItemObject.BankID;
                this.Command.Parameters.Add(BankID);

                /*SqlParameter bankObject = new SqlParameter();
                bankObject.ParameterName = "@BankID";
                bankObject.SqlDbType = SqlDbType.Int;
                bankObject.Direction = ParameterDirection.Input;
                bankObject.IsNullable = false;
                bankObject.Value = payAndReceiveItemObject.BankObject;
                this.Command.Parameters.Add(bankObject);*/

                SqlParameter payAndReceiveID = new SqlParameter();
                payAndReceiveID.ParameterName = "@PayAndReceiveID";
                payAndReceiveID.SqlDbType = SqlDbType.Int;
                payAndReceiveID.Direction = ParameterDirection.Input;
                payAndReceiveID.IsNullable = false;
                payAndReceiveID.Value = payAndReceiveItemObject.PayAndReceiveID;
                this.Command.Parameters.Add(payAndReceiveID);

                SqlParameter ChequeNo = new SqlParameter();
                ChequeNo.ParameterName = "@ChequeNo";
                ChequeNo.SqlDbType = SqlDbType.BigInt;
                ChequeNo.Direction = ParameterDirection.Input;
                ChequeNo.IsNullable = false;
                ChequeNo.Value = payAndReceiveItemObject.ChequeNo;
                this.Command.Parameters.Add(ChequeNo);


                SqlParameter DateOfIssue = new SqlParameter();
                DateOfIssue.ParameterName = "@DateOfIssue";
                DateOfIssue.SqlDbType = SqlDbType.DateTime;
                DateOfIssue.Direction = ParameterDirection.Input;
                DateOfIssue.IsNullable = false;
                DateOfIssue.Value = payAndReceiveItemObject.DateOfIssue;
                this.Command.Parameters.Add(DateOfIssue);


                SqlParameter Description = new SqlParameter();
                Description.ParameterName = "@Description";
                Description.SqlDbType = SqlDbType.NVarChar;
                Description.Direction = ParameterDirection.Input;
                Description.IsNullable = true;
                Description.Value = payAndReceiveItemObject.Description;
                this.Command.Parameters.Add(Description);



                SqlParameter Payee = new SqlParameter();
                Payee.ParameterName = "@Payee";
                Payee.SqlDbType = SqlDbType.NVarChar;
                Payee.Direction = ParameterDirection.Input;
                Payee.IsNullable = false;
                Payee.Value = payAndReceiveItemObject.Payee;
                this.Command.Parameters.Add(Payee);

                SqlParameter status = new SqlParameter();
                status.ParameterName = "@Status";
                status.SqlDbType = SqlDbType.TinyInt;
                status.Direction = ParameterDirection.Input;
                status.IsNullable = false;
                status.Value = payAndReceiveItemObject.Status;
                this.Command.Parameters.Add(status);

                if (controlConnection)
                    this.BeginTransaction();

                this.Command.ExecuteNonQuery();

                if (controlConnection)
                    this.CommitTransaction();

            }
            catch (Exception ex)
            {
                if (controlConnection)
                    this.RollBackTransaction();
                throw ex;
            }


        }

        /// <summary>
        /// this method is for Update a object of BLL.BLLPayAndReceiveItem to table by ChequeNo
        /// this method check connection if connection is open Update object to table
        /// </summary>
        /// <param name="payAndReceiveItemObject" Type="BLL.BLLPayAndReceiveItem"></param>
        /// <param name="targetChequeNo" Type="int"></param>
        /// <return>this type is void and Do not return</return>
        public void Update(BLL.BLLPayAndReceiveItem payAndReceiveItemObject, int targetChequeNo)
        {
            bool controlConnection = !(this.ConnectionState == System.Data.ConnectionState.Open);
            this.Command.CommandText = "uspPayAndReceiveItemUpdate";
            this.Command.CommandType = CommandType.StoredProcedure;

            try
            {
                this.Command.Parameters.Clear();

                SqlParameter AccountNo = new SqlParameter();
                AccountNo.ParameterName = "@AccountNo";
                AccountNo.SqlDbType = SqlDbType.BigInt;
                AccountNo.Direction = ParameterDirection.Input;
                AccountNo.IsNullable = false;
                AccountNo.Value = payAndReceiveItemObject.AcountNo;
                this.Command.Parameters.Add(AccountNo);

                SqlParameter Amount = new SqlParameter();
                Amount.ParameterName = "@Amount";
                Amount.SqlDbType = SqlDbType.BigInt;
                Amount.Direction = ParameterDirection.Input;
                Amount.IsNullable = false;
                Amount.Value = payAndReceiveItemObject.Amount;
                this.Command.Parameters.Add(Amount);

                SqlParameter BranchName = new SqlParameter();
                BranchName.ParameterName = "@BranchName";
                BranchName.SqlDbType = SqlDbType.NVarChar;
                BranchName.Direction = ParameterDirection.Input;
                BranchName.IsNullable = false;
                BranchName.Value = payAndReceiveItemObject.BranchName;
                this.Command.Parameters.Add(BranchName);

                SqlParameter BankID = new SqlParameter();
                BankID.ParameterName = "@BankID";
                BankID.SqlDbType = SqlDbType.Int;
                BankID.Direction = ParameterDirection.Input;
                BankID.IsNullable = false;
                BankID.Value = payAndReceiveItemObject.BankID;
                this.Command.Parameters.Add(BankID);

                /* SqlParameter bankObject = new SqlParameter();
                 BranchName.ParameterName = "@BankID";
                 BranchName.SqlDbType = SqlDbType.Int;
                 BranchName.Direction = ParameterDirection.Input;
                 BranchName.IsNullable = false;
                 BranchName.Value = 5;
                 this.Command.Parameters.Add(bankObject);*/

                SqlParameter payAndReceiveID = new SqlParameter();
                payAndReceiveID.ParameterName = "@PayAndReceiveID";
                payAndReceiveID.SqlDbType = SqlDbType.Int;
                payAndReceiveID.Direction = ParameterDirection.Input;
                payAndReceiveID.IsNullable = false;
                payAndReceiveID.Value = payAndReceiveItemObject.PayAndReceiveID;
                this.Command.Parameters.Add(payAndReceiveID);

                SqlParameter ChequeNo = new SqlParameter();
                ChequeNo.ParameterName = "@ChequeNo";
                ChequeNo.SqlDbType = SqlDbType.BigInt;
                ChequeNo.Direction = ParameterDirection.Input;
                ChequeNo.IsNullable = false;
                ChequeNo.Value = targetChequeNo;
                this.Command.Parameters.Add(ChequeNo);


                SqlParameter DateOfIssue = new SqlParameter();
                DateOfIssue.ParameterName = "@DateOfIssue";
                DateOfIssue.SqlDbType = SqlDbType.DateTime;
                DateOfIssue.Direction = ParameterDirection.Input;
                DateOfIssue.IsNullable = false;
                DateOfIssue.Value = payAndReceiveItemObject.DateOfIssue;
                this.Command.Parameters.Add(DateOfIssue);


                SqlParameter Description = new SqlParameter();
                Description.ParameterName = "@Description";
                Description.SqlDbType = SqlDbType.NVarChar;
                Description.Direction = ParameterDirection.Input;
                Description.IsNullable = true;
                Description.Value = payAndReceiveItemObject.Description;
                this.Command.Parameters.Add(Description);



                SqlParameter Payee = new SqlParameter();
                Payee.ParameterName = "@Payee";
                Payee.SqlDbType = SqlDbType.NVarChar;
                Payee.Direction = ParameterDirection.Input;
                Payee.IsNullable = false;
                Payee.Value = payAndReceiveItemObject.Payee;
                this.Command.Parameters.Add(Payee);

                SqlParameter status = new SqlParameter();
                status.ParameterName = "@Status";
                status.SqlDbType = SqlDbType.TinyInt;
                status.Direction = ParameterDirection.Input;
                status.IsNullable = false;
                status.Value = payAndReceiveItemObject.Status;
                this.Command.Parameters.Add(status);

                if (controlConnection)
                    this.BeginTransaction();

                this.Command.ExecuteNonQuery();

                if (controlConnection)
                    this.CommitTransaction();

            }
            catch (Exception ex)
            {
                if (controlConnection)
                    this.RollBackTransaction();
                throw ex;
            }
        }

        /// <summary>
        /// this method is for Delete a row from table that field name is this fieldname and value is this value
        /// this method check connection if connection is open Delete a row
        /// </summary>
        /// <param name="fieldName" Type="string"></param>
        /// <param name="value" Type="object"></param>
        /// <return>this type is void and Do not return</return>
        //public void Delete(ChequeManagement.BLL.BLLPayAndReceiveItem.PayAndReceiveItemField fieldName, object value)
        //{
        //    bool controlConnection = !(this.ConnectionState == System.Data.ConnectionState.Open);
        //    this.Command.CommandText = "uspPayAndReceiveItemDeleteByField";
        //    this.Command.CommandType = CommandType.StoredProcedure;

        //    try
        //    {
        //        this.Command.Parameters.Clear();

        //        this.Command.Parameters.Add(new SqlParameter("@fieldName", fieldName));
        //        this.Command.Parameters.Add(new SqlParameter("@value", value));

        //        if (controlConnection)
        //            this.BeginTransaction();
        //        this.Command.ExecuteNonQuery();

        //        if (controlConnection)
        //            this.CommitTransaction();

        //    }
        //    catch (Exception ex)
        //    {
        //        if (controlConnection)
        //            this.RollBackTransaction();
        //        throw ex;
        //    }
        //}

        /// <summary>
        /// this method is for Delete a row from table
        /// this method check connection if connection is open Delete a row
        /// </summary>
        /// <param name="pkChequeNo" Type="int"></param>
        /// <return>this type is void and Do not return</return>
        public void Delete(int pkChequeNo)
        {
            bool controlConnection = !(this.ConnectionState == System.Data.ConnectionState.Open);
            this.Command.CommandText = "uspPayAndReceiveItemDeleteByPK";
            this.Command.CommandType = CommandType.StoredProcedure;

            try
            {
                this.Command.Parameters.Clear();

                SqlParameter chequeNo = new SqlParameter();
                chequeNo.ParameterName = "@chequeNo";
                chequeNo.SqlDbType = SqlDbType.BigInt;
                chequeNo.Direction = ParameterDirection.Input;
                chequeNo.IsNullable = false;
                chequeNo.Value = pkChequeNo;
                this.Command.Parameters.Add(chequeNo);

                if (controlConnection)
                    this.BeginTransaction();
                this.Command.ExecuteNonQuery();
                if (controlConnection)
                    this.CommitTransaction();

            }
            catch (Exception ex)
            {
                if (controlConnection)
                    this.RollBackTransaction();
                throw ex;
            }

        }

        /// <summary>
        /// this method is for FetchAll all rows from table
        /// this method check connection if connection is open FetchAll all rows from table
        /// </summary>
        /// <param name="payAndReceiveItemDT" Type="DataTable"></param>
        /// <return>this type is void but result return to DataTable </return>
        public void FetchAll(DataTable payAndReceiveItemDT)
        {
            bool controlConnection = !(this.ConnectionState == System.Data.ConnectionState.Open);
            SqlDataAdapter sqlDataAdapter = new SqlDataAdapter(this.Command);
            this.Command.CommandText = "uspPayAndReceiveItemFetchAll";
            this.Command.CommandType = CommandType.StoredProcedure;
            try
            {
                this.Command.Parameters.Clear();

                if (controlConnection)
                    this.BeginTransaction();
                sqlDataAdapter.Fill(payAndReceiveItemDT);

                if (controlConnection)
                    this.CommitTransaction();

            }
            catch (Exception ex)
            {
                if (controlConnection)
                    this.RollBackTransaction();
                throw ex;
            }
        }

        /// <summary>
        /// this method is for FetchAll all rows from table
        /// this method check connection if connection is open FetchAll all rows from table
        /// </summary>
        /// <returns>result return to a list<> of ChequeManagement.BLL.BLLPayAndReceiveItem</returns>
        public List<ChequeManagement.BLL.BLLPayAndReceiveItem> FetchAll()
        {
            bool controlConnection = !(this.ConnectionState == System.Data.ConnectionState.Open);
            SqlDataAdapter sqlDataAdapter = new SqlDataAdapter(this.Command);
            this.Command.CommandText = "uspPayAndReceiveItemFetchAll";
            this.Command.CommandType = CommandType.StoredProcedure;

            try
            {
                this.Command.Parameters.Clear();

                if (controlConnection)
                    this.BeginTransaction();


                List<BLL.BLLPayAndReceiveItem> result = new List<BLL.BLLPayAndReceiveItem>();

                using (IDataReader dataReader = this.Command.ExecuteReader())
                {
                    result = InitialObjectsFromReader(dataReader);
                }

                if (controlConnection)
                    this.CommitTransaction();

                return result;

            }
            catch (Exception ex)
            {
                if (controlConnection)
                    this.RollBackTransaction();
                throw ex;
            }

        }

        /// <summary>
        /// this method is for FetchAll all rows from table by field name that field name value is this vlaue
        /// this method check connection if connection is open FetchAll all rows from table
        /// </summary>
        /// <param name="fieldName" Type="string"></param>
        /// <param name="value" Type="object"></param>
        /// <returns>result return to a list<> of BLL.BLLPayAndReceiveItem</returns>
        public List<BLL.BLLPayAndReceiveItem> FetchByField(ChequeManagement.BLL.BLLPayAndReceiveItem.PayAndReceiveItemField fieldName, object value)
        {
            bool controlConnection = !(this.ConnectionState == System.Data.ConnectionState.Open);
            this.Command.CommandText = "dbo.uspPayAndReceiveItemFetchCondition";
            this.Command.CommandType = CommandType.StoredProcedure;
            try
            {
                this.Command.Parameters.Clear();
                if (controlConnection)
                    this.BeginTransaction();

                this.Command.Parameters.Add(new SqlParameter("@condition", "[PayAndReceiveItem].[" + fieldName + "] = N'" + value.ToString() + "'"));

                List<BLL.BLLPayAndReceiveItem> result = new List<BLL.BLLPayAndReceiveItem>();
                using (IDataReader dataReader = this.Command.ExecuteReader())
                {
                    result = InitialObjectsFromReader(dataReader);
                }

                if (controlConnection)
                    this.CommitTransaction();

                return result;
            }
            catch (Exception ex)
            {
                if (controlConnection)
                    this.RollBackTransaction();
                throw ex;
            }
        }



        /// <summary>
        /// this method is for FetchAll all rows from table by field name that field name value is this vlaue
        /// this method check connection if connection is open FetchAll all rows from table
        /// </summary>
        /// <param name="fieldName" Type="string"></param>
        /// <param name="value" Type="object"></param>
        /// <param name="BLLPayAndReceiveItemDT" Type="DataTable"></param>
        /// <return>this type is void but return value to DataTable </return>
        public void FetchByField(ChequeManagement.BLL.BLLPayAndReceiveItem.PayAndReceiveItemField fieldName, object value, DataTable BLLPayAndReceiveItemDT)
        {
            bool controlConnection = !(this.ConnectionState == System.Data.ConnectionState.Open);
            this.Command.CommandText = "dbo.uspPayAndReceiveItemFetchCondition";
            this.Command.CommandType = CommandType.StoredProcedure;
            SqlDataAdapter sqlDataAdapter = new SqlDataAdapter(this.Command);

            try
            {
                this.Command.Parameters.Clear();

                if (controlConnection)
                    this.BeginTransaction();

                this.Command.Parameters.Add(new SqlParameter("@condition", "[PayAndReceiveItem].[" + fieldName + "] = N'" + value.ToString() + "'"));
                sqlDataAdapter.Fill(BLLPayAndReceiveItemDT);

                if (controlConnection)
                    this.CommitTransaction();
            }
            catch (Exception ex)
            {
                if (controlConnection)
                    this.RollBackTransaction();
                throw ex;
            }


        }

        /// <summary>
        /// this method is for FetchAll all rows from table by ChequeNo 
        /// this method check connection if connection is open FetchAll all rows from table
        /// </summary>
        /// <param name="chequeID" Type="int"></param>
        /// <returns>return a object that type is BLL.BLLPayAndReceiveItem</returns>
        public BLL.BLLPayAndReceiveItem FetchByKey(int chequeID)
        {
            bool controlConnection = !(this.ConnectionState == System.Data.ConnectionState.Open);
            this.Command.CommandText = "uspPayAndReceiveItemFetchByPK";
            this.Command.CommandType = CommandType.StoredProcedure;
            try
            {
                this.Command.Parameters.Clear();

                SqlParameter chequeNo = new SqlParameter();
                chequeNo.ParameterName = "@ChequeNo";
                chequeNo.SqlDbType = SqlDbType.BigInt;
                chequeNo.Direction = ParameterDirection.Input;
                chequeNo.IsNullable = false;
                chequeNo.Value = chequeID;
                this.Command.Parameters.Add(chequeNo);

                if (controlConnection)
                    this.BeginTransaction();


                BLL.BLLPayAndReceiveItem payAndReceiveItemObject = new BLL.BLLPayAndReceiveItem();

                using (IDataReader dataReader = this.Command.ExecuteReader())
                {
                    if (dataReader.Read())
                        InitialBusinessObjectsFromReader(payAndReceiveItemObject, dataReader);
                    else
                        payAndReceiveItemObject = null;
                }

                if (controlConnection)
                    this.CommitTransaction();


                return payAndReceiveItemObject;
            }
            catch (Exception ex)
            {
                if (controlConnection)
                    this.RollBackTransaction();
                throw ex;

            }

        }

        /// <summary>
        /// this method is for FetchAll all rows from table by condition 
        /// this method check connection if connection is open FetchAll all rows from table
        /// </summary>
        /// <param name="condition" Type="string"></param>
        /// <param name="payAndReceiveItemDT" Type="DataTable"></param>
        /// <return>this type is void but return value to DataTable </return>
        public void FetchAllByCondition(string condition, DataTable payAndReceiveItemDT)
        {
            bool controlConnection = !(this.ConnectionState == System.Data.ConnectionState.Open);
            this.Command.CommandText = "dbo.uspPayAndReceiveItemFetchCondition";
            this.Command.CommandType = CommandType.StoredProcedure;
            SqlDataAdapter sqlDataAdapter = new SqlDataAdapter(this.Command);

            try
            {
                this.Command.Parameters.Clear();

                if (controlConnection)
                    this.BeginTransaction();
                this.Command.Parameters.Add("@condition", condition);
                sqlDataAdapter.Fill(payAndReceiveItemDT);

                if (controlConnection)
                    this.CommitTransaction();
            }
            catch (Exception ex)
            {
                if (controlConnection)
                    this.RollBackTransaction();
                throw ex;
            }

        }


        /// <summary>
        /// this method give columns value by number column
        /// </summary>
        /// <param name="dataReader" Type="IDataReader"></param>
        /// <returns>return a list<> that value is table columns value</returns>
        private List<BLL.BLLPayAndReceiveItem> InitialObjectsFromReader(IDataReader dataReader)
        {
            List<BLL.BLLPayAndReceiveItem> payAndReceiveItemList = new List<BLL.BLLPayAndReceiveItem>();

            int accountNo = dataReader.GetOrdinal("AccountNo");
            int amount = dataReader.GetOrdinal("Amount");
            int branchName = dataReader.GetOrdinal("BranchName");
            int bankID = dataReader.GetOrdinal("BankID");
            int payAndReceiveID = dataReader.GetOrdinal("PayAndReceiveID");
            int chequeNo = dataReader.GetOrdinal("ChequeNo");
            int dateOfIssue = dataReader.GetOrdinal("DateOfIssue");
            int description = dataReader.GetOrdinal("Description");
            int payee = dataReader.GetOrdinal("Payee");
            int status = dataReader.GetOrdinal("Status");
            int PayAndReceiveID = dataReader.GetOrdinal("PayAndReceiveID");

            while (dataReader.Read())
            {
                BLL.BLLPayAndReceiveItem BLLPayAndReceiveItemobject = new BLL.BLLPayAndReceiveItem();

                BLLPayAndReceiveItemobject.AcountNo = dataReader.GetInt64(accountNo);
                BLLPayAndReceiveItemobject.Amount = dataReader.GetDecimal(amount);
                BLLPayAndReceiveItemobject.BranchName = dataReader.GetString(branchName);
                BLLPayAndReceiveItemobject.PayAndReceiveID = dataReader.GetInt32(payAndReceiveID);
                BLLPayAndReceiveItemobject.ChequeNo = dataReader.GetInt64(chequeNo);
                BLLPayAndReceiveItemobject.DateOfIssue = dataReader.GetDateTime(dateOfIssue);
                BLLPayAndReceiveItemobject.Description = dataReader.GetString(description);
                BLLPayAndReceiveItemobject.Payee = dataReader.GetString(payee);
                BLLPayAndReceiveItemobject.PayAndReceiveID = dataReader.GetInt32(payAndReceiveID);
                
                Byte statusInt = dataReader.GetByte(status);
                switch (statusInt)
                {
                    case 0:
                        {
                            BLLPayAndReceiveItemobject.Status = BLL.ChequeStatus.DeliverReturned;
                            break;
                        }
                    case 1:
                        {
                            BLLPayAndReceiveItemobject.Status = BLL.ChequeStatus.DirectCash;
                            break;
                        }
                    case 2:
                        {
                            BLLPayAndReceiveItemobject.Status = BLL.ChequeStatus.DirectReceipt;
                            break;
                        }
                    case 3:
                        {
                            BLLPayAndReceiveItemobject.Status = BLL.ChequeStatus.DirectReturn;
                            break;
                        }
                    case 4:
                        {
                            BLLPayAndReceiveItemobject.Status = BLL.ChequeStatus.Dispensed;
                            break;
                        }
                    case 5:
                        {
                            BLLPayAndReceiveItemobject.Status = BLL.ChequeStatus.Gived;
                            break;
                        }
                    case 6:
                        {
                            BLLPayAndReceiveItemobject.Status = BLL.ChequeStatus.InReceipt;
                            break;
                        }
                    case 7:
                        {
                            BLLPayAndReceiveItemobject.Status = BLL.ChequeStatus.NotPayed;
                            break;
                        }
                    case 8:
                        {
                            BLLPayAndReceiveItemobject.Status = BLL.ChequeStatus.NotReceipt;
                            break;
                        }
                    case 9:
                        {
                            BLLPayAndReceiveItemobject.Status = BLL.ChequeStatus.Payed;
                            break;
                        }
                    case 10:
                        {
                            BLLPayAndReceiveItemobject.Status = BLL.ChequeStatus.Receipt;
                            break;
                        }
                    case 11:
                        {
                            BLLPayAndReceiveItemobject.Status = BLL.ChequeStatus.Retrieve;
                            break;
                        }
                    case 12:
                        {
                            BLLPayAndReceiveItemobject.Status = BLL.ChequeStatus.Returned;
                            break;
                        }
                    default:

                        break;
                }



                payAndReceiveItemList.Add(BLLPayAndReceiveItemobject);
            }

            return payAndReceiveItemList;
        }


        /// <summary>
        /// this method give columns value by number column
        /// </summary>
        /// <param name="payAndReceiveItemObject" Type="BLL.BLLPayAndReceiveItem"></param>
        /// <param name="dataReader" Type="IDataReader"></param>
        /// <returns>this method is void but return a object of BLL.BLLPayAndReceiveItem that value is table columns value</returns>
        private void InitialBusinessObjectsFromReader(BLL.BLLPayAndReceiveItem payAndReceiveItemObject, IDataReader dataReader)
        {
            int account = dataReader.GetOrdinal("AccountNo");
            
            payAndReceiveItemObject.Amount = dataReader.GetDecimal(dataReader.GetOrdinal(BLL.BLLPayAndReceiveItem.PayAndReceiveItemField.Amount.ToString()));
            
            payAndReceiveItemObject.BranchName = dataReader.GetString(dataReader.GetOrdinal(BLL.BLLPayAndReceiveItem.PayAndReceiveItemField.BranchName.ToString()));
            payAndReceiveItemObject.ChequeNo = dataReader.GetInt64(dataReader.GetOrdinal(BLL.BLLPayAndReceiveItem.PayAndReceiveItemField.ChequeNo.ToString()));
            payAndReceiveItemObject.AcountNo = dataReader.GetInt64(account);
            
            payAndReceiveItemObject.DateOfIssue = dataReader.GetDateTime(dataReader.GetOrdinal(BLL.BLLPayAndReceiveItem.PayAndReceiveItemField.DateOfIssue.ToString()));
            payAndReceiveItemObject.Description = dataReader.GetString(dataReader.GetOrdinal(BLL.BLLPayAndReceiveItem.PayAndReceiveItemField.Description.ToString()));
            payAndReceiveItemObject.PayAndReceiveID = dataReader.GetInt32(dataReader.GetOrdinal(BLL.BLLPayAndReceiveItem.PayAndReceiveItemField.PayAndReceiveID.ToString()));
            payAndReceiveItemObject.Payee = dataReader.GetString(dataReader.GetOrdinal(BLL.BLLPayAndReceiveItem.PayAndReceiveItemField.Payee.ToString()));
            
            
            //payAndReceiveItemObject.Status = dataReader.GetInt32(dataReader.GetOrdinal(BLL.BLLPayAndReceiveItem.PayAndReceiveItemField.Status.ToString()));
            Byte statusInt = dataReader.GetByte(dataReader.GetOrdinal("Status"));
            switch (statusInt)
            {
                case 0:
                    {
                        payAndReceiveItemObject.Status = BLL.ChequeStatus.DeliverReturned;
                        break;
                    }
                case 1:
                    {
                        payAndReceiveItemObject.Status = BLL.ChequeStatus.DirectCash;
                        break;
                    }
                case 2:
                    {
                        payAndReceiveItemObject.Status = BLL.ChequeStatus.DirectReceipt;
                        break;
                    }
                case 3:
                    {
                        payAndReceiveItemObject.Status = BLL.ChequeStatus.DirectReturn;
                        break;
                    }
                case 4:
                    {
                        payAndReceiveItemObject.Status = BLL.ChequeStatus.Dispensed;
                        break;
                    }
                case 5:
                    {
                        payAndReceiveItemObject.Status = BLL.ChequeStatus.Gived;
                        break;
                    }
                case 6:
                    {
                        payAndReceiveItemObject.Status = BLL.ChequeStatus.InReceipt;
                        break;
                    }
                case 7:
                    {
                        payAndReceiveItemObject.Status = BLL.ChequeStatus.NotPayed;
                        break;
                    }
                case 8:
                    {
                        payAndReceiveItemObject.Status = BLL.ChequeStatus.NotReceipt;
                        break;
                    }
                case 9:
                    {
                        payAndReceiveItemObject.Status = BLL.ChequeStatus.Payed;
                        break;
                    }
                case 10:
                    {
                        payAndReceiveItemObject.Status = BLL.ChequeStatus.Receipt;
                        break;
                    }
                case 11:
                    {
                        payAndReceiveItemObject.Status = BLL.ChequeStatus.Retrieve;
                        break;
                    }
                case 12:
                    {
                        payAndReceiveItemObject.Status = BLL.ChequeStatus.Returned;
                        break;
                    }
                default:

                    break;
            }

     
            

        }
    }

}

